import re

#no other way to determine if something is a compiled re object
CompiledREType = type(re.compile("re module has some problems"))

class REPredicate(object):
    def __init__(self, compiledRE):
        if not isinstance(compiledRE, CompiledREType):
            raise TypeError, "RE Predicates can only be created with compiled REs"
        self.compiledRE = compiledRE

    def __call__(self, aString):
        return bool(self.compiledRE.search(aString))

    @classmethod
    def fromString(cls, aString):
        return cls(re.compile(aString))
